<#assign path = request.getContextPath() />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>部门管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="${path}/static/css/font.css">
        <link rel="stylesheet" href="${path}/static/css/css.css">
		<link rel="stylesheet" type="text/css" href="${path}/static/css/treeview.css"/>
		<link rel="stylesheet" type="text/css" href="${path}/static/css/organManage.css"/>
		<link rel="stylesheet" type="text/css" href="${path}/static/css/xadmin.css"/>
		<script type="text/javascript" src="${path}/static/js/jquery.min.js"></script>
        <script type="text/javascript" src="${path}/static/lib/layui/layui.js"></script>
        <script type="text/javascript" src="${path}/static/js/xadmin.js"></script>
    </head>
    <body>
	   <div class="x-nav">
			<a href="#">首页</a>
			<span>&gt;</span>
			<a><cite>部门管理</cite></a>
		</div>
        <div class="layui-fluid">
            <div class="layui-row">
				<div id="btns" class="btns"> 
					<!-- <button type="button" class="btn">返回</button> -->
					<button type="button" class="btn">导入</button>
					<button type="button" class="btn-w">导入模板</button>
				</div>
				
				<div id="main" class="trim">
					<ul id="browser" class="filetree treeview-famfamfam">
						<#if datas?? && (datas?size>0)>
						<#list datas as item>
						 <li class="folder">
                             <span class="folder">${item.name}</span>
                             <ul>
                               <#if item.subs?? && (item.subs?size>0)>
                                   <#list item.subs as secSub>
                                        <li>
                                            <span class="folder">${secSub.name}</span>
                                            <ul>
												<#if secSub.subs?? && (secSub.subs?size>0)>
													<#list secSub.subs as thiSub>
												        <li>
                                                            <span class="file">${thiSub.name}</span>
                                                        </li>
													</#list>
												</#if>
                                                <li>
                                                    <button id="add" name="${secSub.id}">添加</button>
                                                    <button id="edit">编辑</button>
                                                    <button id="del">删除</button>
                                                    <input type="text" value="${secSub.id}" style="display: none">
                                                </li>
                                            </ul>
                                        </li>
								   </#list>
								   <#else>
								   <li>
                                       <button id="add" name="${item.id}">添加</button>
                                       <button id="edit">编辑</button>
                                       <button id="del">删除</button>
                                       <input type="text" value="${item.id}" style="display: none">
                                   </li>
							   </#if>
                             </ul>
                         </li>
						</#list>
						<#else>

						</#if>
                        <li>
                            <button id="add" name="0">添加</button>
                            <input type="text" value="0" style="display: none">
                        </li>
					</ul>
				</div>
            </div>
        </div>
    </body>
	<script src="${path}/static/js/treeview.js" type="text/javascript"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		$("#browser").treeview({
		toggle: function() {
			console.log("%s was toggled.", $(this).find(">span").text());
		}
	});

		$("#add").click(function(obj) {
            var parent =  obj.currentTarget.attributes["name"].value;
			var name = "dads";
			$.ajax({
				url:'',
				type:'POST',
				data:{
				    parentId: parent,
					name:name,
				},
				success: function (res) {
					console.log(res);
					if (res.status == 200) {
					    layer.msg("添加成功",{
					        icon:6
						}, function () {
							location.reload();
                        });
					}
                }
			});

			// var branches = $("<li><span class='folder'>New Sublist</span><ul>" +
			// 	"<li><span class='file'>Item1</span></li>" +
			// 	"<li><span class='file'>Item2</span></li></ul></li>").appendTo("#browser");
			// $("#browser").treeview({
			// 	add: branches
			// });
		});
		$("#edit").click(function() {
		
			
		});
		
		$("#del").click(function() {
			
		});
	});
	
	</script>
</html>
